package com.wg.springbootencoding.servlet;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.web.filter.CharacterEncodingFilter;

import javax.servlet.Filter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description:
 * @Author WuGang
 * @Date 2021/10/21 18:55
 * @Version 1.0
 */
@WebServlet(urlPatterns = "/myservlet") //这里相当于控制层就可以直接访问这个地址了  得在入口类让他扫描到
public class MyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.getWriter().println("你好世界中文乱码yingwen");
//            统一设置浏览器的编码格式  不同浏览器编码格式不一样即便是你过滤器里面设置了也不行  只设置这个也不行
            resp.setContentType("text/html;character=utf-8");
            resp.getWriter().flush();
            resp.getWriter().close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
